'''设置元素等待'''
from selenium import webdriver
'''
# 显示等待
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.maximize_window()
element = WebDriverWait(driver,5,0.5).until(
    EC.presence_of_element_located((By.ID, "kw"))
)
element.send_keys('selenium')
'''

from selenium.common.exceptions import NoSuchElementException
from time import ctime

driver = webdriver.Chrome()
driver.maximize_window()

# 设置隐式等待为10秒
driver.implicitly_wait(10)
driver.get('https://www.baidu.com')

try:
    print(ctime())
    driver.find_element_by_id('kw22').send_keys('selenium')
except NoSuchElementException as e:
    print(e)
finally:
    print(ctime())
    driver.quit()